
function MovesHistory(){
	
	this.moves = [];
	this.current = 0;
	
	this.add = function(move){
		if(this.moves.length == 0){
			this.moves.push(move);
			this.current = this.moves.length - 1;
			return true;
		}
		
		//user decides to go few steps back, need to remove obsolete history, only if played back
		//if(this.current != this.moves.length - 1){
		if((this.current > 0 && this.current < this.moves.length - 1) || ((this.current == 0 || this.current == this.moves.length - 1) && !player.last.playDirection)){
			var number_steps_to_remove = this.moves.length - this.current;
			this.moves.splice(this.current,number_steps_to_remove);
		}
		
		this.moves.push(move);
		this.current = this.moves.length - 1;
		return true;
		
	};
	
	this.setCurrentPointer = function(i){
		this.current = i;
	};
	
	this.getTotal = function(){
		return this.moves.length;
	};
	
	this.getMoves = function(){
		return this.moves;
	};
	
	this.getPointer = function(){
		return this.current;
	};
	
	this.getJSON = function(){
		var str = JSON.stringify(this);
		//console.log(movesHistory.getJSON());
		return str;
	};
	
}

var movesHistory = new MovesHistory();